package com.carey.yygh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.carey.yygh.cmn.client.DictFeignClient;
import com.carey.yygh.enums.DictEnum;
import com.carey.yygh.model.user.Patient;
import com.carey.yygh.user.service.PatientService;
import com.carey.yygh.user.mapper.PatientMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author carey-
* @description 针对表【patient(就诊人表)】的数据库操作Service实现
* @createDate 2022-05-18 02:06:11
*/
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient>
    implements PatientService{

    @Autowired
    private PatientMapper patientMapper;

    @Autowired
    private DictFeignClient dictFeignClient;
    @Override
    public List<Patient> findAll(Long userId) {
        if (null == userId){
            return null;
        }
        QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<Patient> list = patientMapper.selectList(queryWrapper);
        //List<Patient> list = patientMapper.selectAllByUserId(userId);
        list.forEach(patient -> {
            this.packPatient(patient);
        });
        return list;
    }

    @Override
    public void savePatient(Patient patient) {
        patientMapper.insert(patient);
    }

    @Override
    public Patient getPatientId(Long id) {
        Patient patient = patientMapper.selectById(id);
        this.packPatient(patient);
        return patient;
    }

    public void packPatient(Patient patient){
        //联系人证件类型
        String certificatesTypeString =
                dictFeignClient.getName(patient.getCertificatesType());
        //省
        String provinceString = dictFeignClient.getName(patient.getProvinceCode());
        //市
        String cityString = dictFeignClient.getName(patient.getCityCode());
        //区
        String districtString = dictFeignClient.getName(patient.getDistrictCode());

        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());

    }
}




